﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZDSoft.TES.Entity.SystemEntity;
using ZDSoft.TES.Core;
using ZDSoft.TES.Service.SystemService;

namespace ZDSoft.TES.Web.Controllers
{
    public class OrganizationController : Controller
    {
        public ActionResult Index()
        {

            IList<Organization> OrganizationList = Container.Instance.Resolve<IOrganizationService>().FindAll();
            TempData["type"] = FindAllType(OrganizationList);
            return View();
        }
        [HttpPost]
        public string Index(string id, string pid, string name)
        {
            id = Container.Instance.Resolve<IOrganizationService>().Create(id, pid, name).ToString();
            return id;
        }
        public string FindAllType(IList<Organization> modle)
        {
            string result = "";
            IList<Organization> OrganizationList = Container.Instance.Resolve<IOrganizationService>().FindAll();
            foreach (Organization one in Container.Instance.Resolve<IOrganizationService>().FindAll())
            {
                if (one.Parent == null)
                {
                    result += "{id:" + one.ID + ",pId:" + 0 + ",name:\"" + one.OrganizationName + "\",open:false,iconOpen:\"../../Scripts/zTree/css/zTreeStyle/img/diy/1_open.png\",iconClose:\"../../Scripts/zTree/css/zTreeStyle/img/diy/1_close.png\"},";
                }
                else
                {
                    result += "{id:" + one.ID + ",pId:" + one.Parent.ID + ",name:\"" + one.OrganizationName + "\",open:true,icon: \"../../Scripts/zTree/css/zTreeStyle/img/diy/3.png\"},";
                }
            }
            return result;
        }

        public void GetOrganizationByID(string id)
        {
            Container.Instance.Resolve<IOrganizationService>().Delete(int.Parse(id));
        }


    }
}




